home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / WASM211B.LZH / VIDEO2.INC < prev   
Text File  |  1988-03-02  |  12KB  |  504 lines

  1. ;=============================================================================
  2. ; High Level Video Routines
  3. ;
  4. ; These are routines to display formatted text strings.  All registers are
  5. ; preserved except those used to return parameters.  All parameters are passed
  6. ; through the registers.  VIDEO1.INC must be included in the source code.
  7. ; VIDEO_INIT must be called before any of these routines. It is assumed that
  8. ; DS = ES = CS.
  9.  
  10. ;================================================
  11. ; Global data.
  12.  
  13. ;--- display attributes
  14.  
  15. Video_Norm Db 07h       ;normal
  16. Video_Emph Db 02h       ;emphasized (underline)
  17. Video_High Db 70h       ;highlight (reverse video)
  18. Video_Bold Db 0fh       ;bold (intense)
  19.  
  20. ;--- attribute stack
  21.  
  22. Video_AtrM Equ 10       ;maximum stack entries (n > 0)
  23. Video_AtrN Dw 0         ;present stack number
  24. Video_AtrS Db 07h       ;start of stack
  25.  Ds Video_AtrM, ?       ;rest of stack
  26.  
  27. ;--- string formatting controls
  28.  
  29. FrmEnd Equ 0            ;end of string
  30. FrmCtl Equ 1            ;control character mask
  31. FrmNorm Equ 2           ;switch to normal attribute
  32. FrmEmph Equ 3           ;switch to emphasized
  33. FrmHigh Equ 4           ;switch to highlight
  34. FrmBold Equ 5           ;switch to bold
  35. FrmAtr Equ 6            ;user defined attribute
  36. FrmPush Equ 7           ;push the present attribute
  37. FrmPop Equ 8            ;pop an attribute
  38. FrmHor Equ 9            ;horizontally repeated character (left to right)
  39. FrmVer Equ 10           ;vertically repeated character (up to down)
  40. FrmStr Equ 11           ;nested string
  41. FrmLoc Equ 12           ;locate cursor
  42.  
  43. Video_StrM Equ 10       ;maximum nested strings
  44.  
  45. ;================================================
  46. ; Write a formatted string. Note: uses (32 = 
  47. ; Video_AtrM * 2 + 14) stack bytes.
  48. ;
  49. ; In: SI= string location.
  50.  
  51. Video_Wstr Proc Near
  52.  Pushf
  53.  Push Ax
  54.  Push Bx
  55.  Push Cx
  56.  Push Dx
  57.  Push Di
  58.  Push Si
  59.  Push Bp
  60.  Sub Sp, Video_AtrM * 2 + 2     ;room for local data
  61.  Mov Bp, Sp
  62.  
  63.  Cld
  64.  Mov Word [Bp], 0               ;clear nested string stack
  65.  Mov Di, Video_AtrN             ;get the present stack number
  66.  Mov Bl, [Video_AtrS + Di]      ;get attribute
  67.  
  68. ;--- loop for each byte in the string
  69.  
  70. Vidwst1
  71.  Lodsb                  ;get the next byte
  72.  Cmp Al, FrmEnd     ;check if end of string
  73.  Je Vidwst5
  74.  Cmp Al, 32             ;check if control character
  75.  Jb Vidwst2
  76.  Call Video_Wchr        ;write character
  77.  Jmps Vidwst1
  78.  
  79. ;--- control character
  80.  
  81. Vidwst2
  82.  Mov Di, Offset Video_Ftab      ;location of table
  83.  
  84. Vidwst3
  85.  Cmp Byte [Di], -1      ;check if end of table
  86.  Je Vidwst1             ;jump if so, ignore this character
  87.  Cmp Al, [Di]           ;check if match command
  88.  Je Vidwst4             ;jump if so, call command routine
  89.  Add Di, 3              ;next location
  90.  Jmps Vidwst3           ;loop back until end of table or match
  91.  
  92. Vidwst4
  93.  Call Word [Di + 1]     ;call the routine
  94.  Jmps Vidwst1
  95.  
  96. ;--- check if within nested string
  97.  
  98. Vidwst5
  99.  Mov Ax, [Bp]   ;get the number
  100.  Or Ax, Ax      ;check if any entries
  101.  Jz Vidwst6
  102.  
  103.  Dec Ax          ;reduce count
  104.  Mov [Bp], Ax    ;save it
  105.  Mov Di, Ax
  106.  Shl Di                 ;times two
  107.  Mov Si, [Bp + 2 + Di]  ;get the saved offset
  108.  Jmps Vidwst1           ;continue
  109.  
  110. ;--- finished, save the attribute in the attribute stack
  111.  
  112. Vidwst6
  113.  Mov Di, Video_AtrN             ;get the present stack number
  114.  Mov [Video_AtrS + Di], Bl      ;save attribute
  115.  
  116.  Add Sp, Video_AtrM * 2 + 2     ;fix stack
  117.  Pop Bp
  118.  Pop Si
  119.  Pop Di
  120.  Pop Dx
  121.  Pop Cx
  122.  Pop Bx
  123.  Pop Ax
  124.  Popf
  125.  Ret
  126.  Endp           ;Video_Wfstr
  127.  
  128. ;------------------------------------------------
  129. ; This is the table to access the formatting
  130. ; routines below. The table consists of a format
  131. ; command byte followed by the 16 bit address of
  132. ; the routine to handle the command.  The table
  133. ; is terminated with a -1 (FFH).
  134.  
  135. Video_Ftab Label Byte
  136.  Db FrmCtl, Offset Vidwstr1
  137.  Db FrmNorm, Offset Vidwstr2
  138.  Db FrmEmph, Offset Vidwstr3
  139.  Db FrmHigh, Offset Vidwstr4
  140.  Db FrmBold, Offset Vidwstr5
  141.  Db FrmAtr, Offset Vidwstr6
  142.  Db FrmPush, Offset Vidwstr7
  143.  Db FrmPop, Offset Vidwstr8
  144.  Db FrmHor, Offset Vidwstr9
  145.  Db FrmStr, Offset Vidwstr10
  146.  Db FrmLoc, Offset Vidwstr11
  147.  Db FrmVer, Offset Vidwstr12
  148.  Db -1
  149.  
  150. ;------------------------------------------------
  151. ; These are the individual routines to handle
  152. ; the special formatting commands.
  153.  
  154. ;--- control character mask
  155.  
  156. Vidwstr1 Proc Near
  157.  Lodsb                  ;get the character
  158.  Call Video_Wchr        ;display
  159.  Ret
  160.  Endp
  161.  
  162. ;--- normal attribute
  163.  
  164. Vidwstr2 Proc Near
  165.  Mov Bl, Video_Norm     ;set to normal attribute
  166.  Ret
  167.  Endp
  168.  
  169. ;--- emphasized attribute
  170.  
  171. Vidwstr3 Proc Near
  172.  Mov Bl, Video_Emph     ;set to normal attribute
  173.  Ret
  174.  Endp
  175.  
  176. ;--- highlighted attribute
  177.  
  178. Vidwstr4 Proc Near
  179.  Mov Bl, Video_High     ;set to normal attribute
  180.  Ret
  181.  Endp
  182.  
  183. ;--- bold attribute
  184.  
  185. Vidwstr5 Proc Near
  186.  Mov Bl, Video_Bold     ;set to normal attribute
  187.  Ret
  188.  Endp
  189.  
  190. ;--- user defined attribute
  191.  
  192. Vidwstr6 Proc Near
  193.  Lodsb          ;get the attribute
  194.  Mov Bl, Al     ;set attribute
  195.  Ret
  196.  Endp
  197.  
  198. ;--- push the present attribute
  199.  
  200. Vidwstr7 Proc Near
  201.  Mov Ax, Video_AtrN     ;get the present stack number
  202.  Cmp Ax, Video_AtrM - 1 ;check if stack full
  203.  Jae Vidwstr71
  204.  
  205.  Mov Di, Ax                     ;load index
  206.  Mov [Video_AtrS + Di], Bl      ;save the present attribute
  207.  
  208.  Inc Ax                 ;increment stack
  209.  Mov Video_AtrN, Ax     ;save it
  210.  
  211. Vidwstr71 Ret
  212.  Endp
  213.  
  214. ;--- pop an attribute
  215.  
  216. Vidwstr8 Proc Near
  217.  Mov Ax, Video_AtrN     ;get the present stack number
  218.  Or Ax, Ax              ;check if at bottom
  219.  Jz Vidwstr81
  220.  
  221.  Dec Ax                         ;reduce stack number
  222.  Mov Di, Ax                     ;load index
  223.  Mov Bl, [Video_AtrS + Di]      ;set the present attribute
  224.  
  225.  Mov Video_AtrN, Ax     ;save stack number
  226. Vidwstr81 Ret
  227.  Endp
  228.  
  229. ;--- repeat display a character
  230.  
  231. Vidwstr9 Proc Near
  232.  Lodsb                  ;get the character
  233.  Push Ax
  234.  Lodsb                  ;load the count
  235.  Mov Cl, Al
  236.  Sub Ch, Ch             ;count in CX
  237.  Pop Ax
  238.  Call Video_Wchrs       ;display characters
  239.  Ret
  240.  Endp
  241.  
  242. ;--- nested string
  243.  
  244. Vidwstr10 Proc Near
  245.  Lodsw                          ;get the offset
  246.  Cmp Word [Bp], Video_StrM      ;check if stack full
  247.  Je Vidwstr101
  248.  
  249.  Mov Di, [Bp]           ;stack entries
  250.  Shl Di                 ;times two
  251.  Mov [Bp + 2 + Di], Si  ;save present location
  252.  Inc Word [Bp]          ;increment entries
  253.  Mov Si, Ax             ;new string location
  254. Vidwstr101 Ret 
  255.  Endp
  256.  
  257. ;--- cursor move
  258.  
  259. Vidwstr11 Proc Near
  260.  Lodsw                  ;load location
  261.  Xchg Ah, Al            ;get row and column in right register halves
  262.  Mov Dx, Ax
  263.  Call Video_Cset        ;set cursor location
  264.  Ret
  265.  Endp
  266.  
  267. ;--- vertically repeated character
  268.  
  269. Vidwstr12 Proc Near
  270.  Lodsb                  ;get the character
  271.  Push Ax
  272.  Lodsb                  ;load the count
  273.  Mov Cl, Al
  274.  Sub Ch, Ch             ;count in CX
  275.  Pop Ax
  276.  Call Video_Cget        ;get the cursor location
  277.  
  278. Vidwstr121
  279.  Push Dx
  280.  Call Video_Wchr        ;display character
  281.  Pop Dx
  282.  Inc Dh                 ;next row
  283.  Call Video_Cset        ;set the cursor location
  284.  Loop Vidwstr121
  285.  Ret
  286.  Endp
  287.  
  288. ;================================================
  289. ; Calculate the horizontal length of the text in
  290. ; a formatted string. Note: uses (32 =
  291. ; Video_AtrM * 2 + 10) stack bytes.  Used for
  292. ; justifying strings.
  293. ;
  294. ; In: SI= string location.
  295. ;
  296. ; Out: BX= length.
  297.  
  298. Video_Scnt Proc Near
  299.  Push Ax
  300.  Push Di
  301.  Push Si
  302.  Push Bp
  303.  Sub Sp, Video_AtrM * 2 + 2     ;room for local data
  304.  Mov Bp, Sp
  305.  
  306.  Sub Bx, Bx             ;clear the count
  307.  Mov Word [Bp], 0       ;clear nested string stack
  308.  
  309. ;--- loop for each byte in the string
  310.  
  311. Vidscn1
  312.  Lodsb                  ;get the next byte
  313.  Cmp Al, FrmEnd         ;check if end of string
  314.  Je Vidscn8
  315.  Cmp Al, 32             ;check if control character
  316.  Jb Vidscn2
  317.  Inc Bx                 ;increment count
  318.  Jmps Vidscn1
  319.  
  320. ;--- control character
  321.  
  322. Vidscn2
  323.  Cmp Al, FrmCtl
  324.  Jne Vidscn3
  325.  Inc Si         ;skip character
  326.  Inc Bx         ;add to total
  327.  Jmps Vidscn1
  328.  
  329. ;--- user attribute
  330.  
  331. Vidscn3
  332.  Cmp Al, FrmAtr
  333.  Jne Vidscn4
  334.  Inc Si         ;skip attribute byte
  335.  Jmps Vidscn1
  336.  
  337. ;--- horizontal repeated byte
  338.  
  339. Vidscn4
  340.  Cmp Al, FrmHor
  341.  Jne Vidscn5
  342.  Inc Si         ;skip character
  343.  Lodsb          ;load length
  344.  Sub Ah, Ah
  345.  Add Bx, Ax     ;add to total
  346.  Jmps Vidscn1
  347.  
  348. ;--- nested string
  349.  
  350. Vidscn5
  351.  Cmp Al, FrmStr
  352.  Jne Vidscn6
  353.  Call Vidwstr10         ;start nested string
  354.  Jmps Vidscn1
  355.  
  356. ;--- cursor move
  357.  
  358. Vidscn6
  359.  Cmp Al, FrmLoc
  360.  Jne Vidscn7
  361.  Inc Si
  362.  Inc Si         ;skip location
  363.  Jmps Vidscn1
  364.  
  365. ;--- vertical repeated byte
  366.  
  367. Vidscn7
  368.  Cmp Al, FrmVer
  369.  Jne Vidscn1
  370.  Inc Si
  371.  Inc Si         ;skip byte and count
  372.  Inc Bx         ;add one for the first byte
  373.  Jmps Vidscn1
  374.  
  375. ;--- check if within nested string
  376.  
  377. Vidscn8
  378.  Mov Ax, [Bp]   ;get the number
  379.  Or Ax, Ax      ;check if any entries
  380.  Jz Vidscn9
  381.  
  382.  Dec Ax          ;reduce count
  383.  Mov [Bp], Ax    ;save it
  384.  Mov Di, Ax
  385.  Shl Di                 ;times two
  386.  Mov Si, [Bp + 2 + Di]  ;get the saved offset
  387.  Jmps Vidscn1           ;continue
  388.  
  389. ;--- finished
  390.  
  391. Vidscn9
  392.  Add Sp, Video_AtrM * 2 + 2     ;fix stack
  393.  Pop Bp
  394.  Pop Si
  395.  Pop Di
  396.  Pop Ax
  397.  Ret
  398.  Endp           ;Video_Scnt
  399.  
  400. ;================================================
  401. ; Write a string padded with some character on
  402. ; both sides.
  403. ;
  404. ; In: SI= string location; AL= pad character;
  405. ; BX= left side pad number; CX= right side pad
  406. ; number.
  407.  
  408. Video_Wstrp Proc Near
  409.  Push Bx
  410.  Push Cx
  411.  Push Di
  412.  Mov Di, Video_AtrN             ;get the present stack number
  413.  Push Cx
  414.  Mov Cx, Bx
  415.  Mov Bl, [Video_AtrS + Di]      ;get attribute
  416.  Call Video_Wchrs               ;write preceding spaces
  417.  Call Video_Wstr                ;write string
  418.  Pop Cx
  419.  Mov Bl, [Video_AtrS + Di]      ;get attribute
  420.  Call Video_Wchrs               ;write following spaces
  421.  Pop Di
  422.  Pop Cx
  423.  Pop Bx
  424.  Ret
  425.  Endp           ;Video_Wstrp
  426.  
  427. ;================================================
  428. ; Write a left justified string.
  429. ;
  430. ; In: SI= string location; AL= pad character;
  431. ; CX= total column width.
  432.  
  433. Video_Wstrl Proc Near
  434.  Pushf
  435.  Cld
  436.  Push Bx
  437.  Push Cx
  438.  Call Video_Scnt        ;get string width
  439.  Cmp Bx, Cx             ;check if too big
  440.  Jbe Vidwsl1
  441.  Mov Bx, Cx             ;set to maximum length
  442. Vidwsl1
  443.  Sub Cx, Bx             ;get difference
  444.  Sub Bx, Bx             ;no padding in front
  445.  Call Video_Wstrp       ;print with padding
  446.  Pop Cx
  447.  Pop Bx
  448.  Popf
  449.  Ret
  450.  Endp           ;Video_Wstrl
  451.  
  452. ;================================================
  453. ; Write a right justified string.
  454. ;
  455. ; In: SI= string location; AL= pad character;
  456. ; CX= total column width.
  457.  
  458. Video_Wstrr Proc Near
  459.  Pushf
  460.  Cld
  461.  Push Bx
  462.  Push Cx
  463.  Call Video_Scnt        ;get string width
  464.  Cmp Bx, Cx             ;check if too big
  465.  Jbe Vidwsr1
  466.  Mov Bx, Cx             ;set to maximum length
  467. Vidwsr1
  468.  Sub Cx, Bx             ;get difference
  469.  Mov Bx, Cx             ;padding is before
  470.  Sub Cx, Cx             ;no padding after
  471.  Call Video_Wstrp       ;print with padding
  472.  Pop Cx
  473.  Pop Bx
  474.  Popf
  475.  Ret
  476.  Endp           ;Video_Wstrr
  477.  
  478. ;================================================
  479. ; Write a center justified string.
  480. ;
  481. ; In: SI= string location; AL= pad character;
  482. ; CX= total column width.
  483.  
  484. Video_Wstrc Proc Near
  485.  Pushf
  486.  Cld
  487.  Push Bx
  488.  Push Cx
  489.  Call Video_Scnt        ;get string width
  490.  Cmp Bx, Cx             ;check if too big
  491.  Jbe Vidwsc1
  492.  Mov Bx, Cx             ;set to maximum length
  493. Vidwsc1
  494.  Sub Cx, Bx             ;get difference
  495.  Mov Bx, Cx
  496.  Shr Bx                 ;divide by two, preceding pad
  497.  Sub Cx, Bx             ;difference is end pad
  498.  Call Video_Wstrp       ;print with padding
  499.  Pop Cx
  500.  Pop Bx
  501.  Popf
  502.  Ret
  503.  Endp           ;Video_Wstrc
  504.